<template>
  <view class="jnpf-wrap jnpf-wrap-workflow">
    <u-form
      :model="dataForm"
      ref="dataForm"
      :errorType="['toast']"
      label-position="left"
      label-width="150"
      label-align="left"
    >
      <u-form-item label="进货单别" v-if="judgeShow('tg001')">
        <u-input
          v-model="dataForm.tg001"
          placeholder="进货单别"
          disabled
        ></u-input>
      </u-form-item>
      <u-form-item label="进货单号" v-if="judgeShow('tg002')">
        <u-input
          v-model="dataForm.tg002"
          placeholder="进货单号"
          disabled
        ></u-input>
      </u-form-item>
      <u-form-item label="进货日期" v-if="judgeShow('tg003')">
        <u-input
          v-model="dataForm.tg003"
          placeholder="进货日期"
          disabled
        ></u-input>
      </u-form-item>
      <u-form-item label="供应商" v-if="judgeShow('tg005')">
        <u-input
          v-model="dataForm.tg005"
          placeholder="供应商"
          disabled
        ></u-input>
      </u-form-item>
      <u-form-item label="供应商全称" v-if="judgeShow('tg021')">
        <u-input
          v-model="dataForm.tg021"
          placeholder="供应商全称"
          disabled
        ></u-input>
      </u-form-item>
      <u-form-item label="项目编号" v-if="judgeShow('tg059')">
        <u-input
          v-model="dataForm.tg059"
          placeholder="项目编号"
          disabled
        ></u-input>
      </u-form-item>
      <u-form-item label="附件" v-if="judgeShow('tg059')">
        <jnpf-file v-model="dataForm.tg059" />
      </u-form-item>
      <u-tabs-swiper
        ref="tabs"
        :list="swiperList"
        :current="current"
        @change="tabsChange"
        :is-scroll="false"
      ></u-tabs-swiper>
      <view v-show="current == 0">
        <u-form-item label="工厂" v-if="judgeShow('tg004')">
          <u-input v-model="dataForm.tg004" disabled></u-input>
        </u-form-item>
        <u-form-item label="备注" v-if="judgeShow('tg016')">
          <u-input v-model="dataForm.tg016" disabled></u-input>
        </u-form-item>
        <u-form-item label="供应商单号" v-if="judgeShow('tg006')">
          <u-input v-model="dataForm.tg006" disabled></u-input>
        </u-form-item>
        <u-form-item label="税种" v-if="judgeShow('tg007')">
          <u-input v-model="dataForm.tg007" disabled></u-input>
        </u-form-item>
        <u-form-item label="件数" v-if="judgeShow('tg025')">
          <u-input v-model="dataForm.tg025" disabled></u-input>
        </u-form-item>
        <u-form-item label="打印次数" v-if="judgeShow('tg012')">
          <u-input v-model="dataForm.tg012" disabled></u-input>
        </u-form-item>
        <u-form-item label="币种" v-if="judgeShow('tg007')">
          <u-input v-model="dataForm.tg007" disabled></u-input>
        </u-form-item>
        <u-form-item label="汇率" v-if="judgeShow('tg008')">
          <u-input v-model="dataForm.tg008" disabled></u-input>
        </u-form-item>
        <u-form-item label="增值税率" v-if="judgeShow('tg030')">
          <u-input v-model="dataForm.tg030" disabled></u-input>
        </u-form-item>
        <u-form-item label="来源单号" v-if="judgeShow('tg048')">
          <u-input v-model="dataForm.tg048" disabled></u-input>
        </u-form-item>
        <u-form-item label="部门编号" v-if="judgeShow('tg049')">
          <u-input v-model="dataForm.tg049" disabled></u-input>
        </u-form-item>
        <u-form-item label="海关手册" v-if="judgeShow('tg044')">
          <u-input v-model="dataForm.tg044" disabled></u-input>
        </u-form-item>
        <u-form-item label="付款条件编号" v-if="judgeShow('tg033')">
          <u-input v-model="dataForm.tg033" disabled></u-input>
        </u-form-item>
        <u-form-item label="签核状态码" v-if="judgeShow('tg042')">
          <u-input v-model="dataForm.tg042" disabled></u-input>
        </u-form-item>
        <u-form-item label="IQC人员工号" v-if="judgeShow('udf11')">
          <u-input v-model="dataForm.udf11" disabled></u-input>
        </u-form-item>
        <u-form-item label="IQC人员名称" v-if="judgeShow('udf12')">
          <u-input v-model="dataForm.udf12" disabled></u-input>
        </u-form-item>
        <u-form-item label="是否检验" v-if="judgeShow('udf10')">
          <u-input v-model="dataForm.udf10" disabled></u-input>
        </u-form-item>
      </view>
      <view v-show="current == 1">
        <u-form-item label="发票种类" v-if="judgeShow('tg009')">
          <u-input v-model="dataForm.tg009" disabled></u-input>
        </u-form-item>
        <u-form-item label="发票号码" v-if="judgeShow('tg011')">
          <u-input v-model="dataForm.tg011" disabled></u-input>
        </u-form-item>
        <u-form-item label="发票日期" v-if="judgeShow('tg027')">
          <u-input v-model="dataForm.tg027" disabled></u-input>
        </u-form-item>
        <u-form-item label="税号" v-if="judgeShow('tg022')">
          <u-input v-model="dataForm.tg022" disabled></u-input>
        </u-form-item>
      </view>
      <view class="jnpf-table" style="margin-top: 24rpx">
        <view
          class="jnpf-table-item"
          style="margin-bottom: 24rpx"
          v-for="(item, i) in purthList"
          :key="i"
        >
          <u-form-item label="序号">
            {{ i + 1 }}
          </u-form-item>
          <u-form-item label="品号" v-if="judgeShow('purthList-th004')">
            <u-input v-model="item.th004" placeholder="品号" disabled></u-input>
          </u-form-item>
          <u-form-item label="品名" v-if="judgeShow('purthList-th005')">
            <u-input v-model="item.th005" placeholder="品名" disabled></u-input>
          </u-form-item>
          <u-form-item label="规格" v-if="judgeShow('purthList-th006')">
            <u-input v-model="item.th006" placeholder="规格" disabled></u-input>
          </u-form-item>
          <u-form-item label="进货数量" v-if="judgeShow('purthList-th007')">
            <u-input
              v-model="item.th007"
              placeholder="进货数量"
              disabled
            ></u-input>
          </u-form-item>
          <u-form-item label="单位" v-if="judgeShow('purthList-th008')">
            <u-input v-model="item.th008" placeholder="单位" disabled></u-input>
          </u-form-item>
          <u-form-item label="仓库" v-if="judgeShow('purthList-th009')">
            <u-input v-model="item.th009" disabled></u-input>
          </u-form-item>
          <u-form-item label="采购单别" v-if="judgeShow('purthList-th011')">
            <u-input v-model="item.th011" disabled></u-input>
          </u-form-item>
          <u-form-item label="采购序号" v-if="judgeShow('purthList-th013')">
            <u-input v-model="item.th013" disabled></u-input>
          </u-form-item>
          <u-form-item label="批号" v-if="judgeShow('purthList-th010')">
            <u-input v-model="item.th010" disabled></u-input>
          </u-form-item>
          <u-form-item label="库存单位" v-if="judgeShow('purthList-th065')">
            <u-input v-model="item.th065" disabled></u-input>
          </u-form-item>
          <u-form-item label="验收数量" v-if="judgeShow('purthList-th015')">
            <u-input v-model="item.th015" disabled></u-input>
          </u-form-item>
          <u-form-item label="验退数量" v-if="judgeShow('purthList-th017')">
            <u-input v-model="item.th017" disabled></u-input>
          </u-form-item>
          <u-form-item label="计价数量" v-if="judgeShow('purthList-th016')">
            <u-input v-model="item.th016" disabled></u-input>
          </u-form-item>
          <u-form-item label="原币单位进价" v-if="judgeShow('purthList-th018')">
            <u-input v-model="item.th018" disabled></u-input>
          </u-form-item>
          <u-form-item label="原币进货金额" v-if="judgeShow('purthList-th019')">
            <u-input v-model="item.th019" disabled></u-input>
          </u-form-item>
          <u-form-item label="原币扣款金额" v-if="judgeShow('purthList-th020')">
            <u-input v-model="item.th020" disabled></u-input>
          </u-form-item>
          <u-form-item label="进货费用" v-if="judgeShow('purthList-th024')">
            <u-input v-model="item.th024" disabled></u-input>
          </u-form-item>
          <u-form-item label="原币税前金额" v-if="judgeShow('purthList-th045')">
            <u-input v-model="item.th045" disabled></u-input>
          </u-form-item>
          <u-form-item label="原币税额" v-if="judgeShow('purthList-th046')">
            <u-input v-model="item.th046" disabled></u-input>
          </u-form-item>
          <u-form-item label="本币税前金额" v-if="judgeShow('purthList-th047')">
            <u-input v-model="item.th047" disabled></u-input>
          </u-form-item>
          <u-form-item label="本币税额" v-if="judgeShow('purthList-th048')">
            <u-input v-model="item.th048" disabled></u-input>
          </u-form-item>
          <u-form-item label="批号说明" v-if="judgeShow('purthList-th067')">
            <u-input v-model="item.th067" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="生产日期" v-if="judgeShow('purthList-th057')">
            <u-input v-model="item.th057" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="有效日期" v-if="judgeShow('purthList-th036')">
            <u-input v-model="item.th036" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="复检日期" v-if="judgeShow('purthList-th037')">
            <u-input v-model="item.th037" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="到货单别" v-if="judgeShow('purthList-thc03')">
            <u-input v-model="item.thc03" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="到货单号" v-if="judgeShow('purthList-thc04')">
            <u-input v-model="item.thc04" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="到货序号" v-if="judgeShow('purthList-thc05')">
            <u-input v-model="item.thc05" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="检验批次" v-if="judgeShow('purthList-thc06')">
            <u-input v-model="item.thc06" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="验收日期" v-if="judgeShow('purthList-th014')">
            <u-input v-model="item.th014" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="扣款说明" v-if="judgeShow('purthList-th025')">
            <u-input v-model="item.th025" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="暂不付款" v-if="judgeShow('purthList-th026')">
            <u-input v-model="item.th026" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="超期码" v-if="judgeShow('purthList-th026')">
            <u-input v-model="item.th026" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="检验状态" v-if="judgeShow('purthList-th028')">
            <span v-if="item.th028 == '0'">免检</span>
            <span v-if="item.th028 == '1'">待检</span>
            <span v-if="item.th028 == '2'">合格</span>
            <span v-if="item.th028 == '3'">不良</span>
            <span v-if="item.th028 == '4'">特检</span>
          </u-form-item>
          <u-form-item label="验退码" v-if="judgeShow('purthList-th029')">
            <u-input v-model="item.th029" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="项目编号" v-if="judgeShow('purthList-th042')">
            <u-input v-model="item.th042" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="备注" v-if="judgeShow('purthList-tg016')">
            <u-input v-model="item.tg016" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="暂估码" v-if="judgeShow('purthList-th080')">
            <u-input v-model="item.th080" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="开票码" v-if="judgeShow('purthList-th031')">
            <u-input v-model="item.th031" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="冲自筹额码" v-if="judgeShow('purthList-th044')">
            <u-input v-model="item.th044" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="本币冲自筹额" v-if="judgeShow('purthList-th052')">
            <u-input v-model="item.th052" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="生成分录" v-if="judgeShow('purthList-th043')">
            <u-input v-model="item.th043" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="借入单别" v-if="judgeShow('purthList-th021')">
            <u-input v-model="item.th021" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="借入单号" v-if="judgeShow('purthList-th022')">
            <u-input v-model="item.th022" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="借入序号" v-if="judgeShow('purthList-th023')">
            <u-input v-model="item.th023" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="已开票数量" v-if="judgeShow('purthList-th054')">
            <u-input v-model="item.th054" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item
            label="已开票扣款金额"
            v-if="judgeShow('purthList-th055')"
          >
            <u-input v-model="item.th055" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="审核码" v-if="judgeShow('purthList-th030')">
            <span v-if="item.th030 == 'Y'">已审核</span>
            <span v-if="item.th030 == 'N'">未审核</span>
            <span v-if="item.th030 == 'V'">作废</span>
          </u-form-item>
          <u-form-item label="审核者" v-if="judgeShow('purthList-th038')">
            <u-input v-model="item.th038" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="报废码" v-if="judgeShow('purthList-th070')">
            <u-input v-model="item.th070" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item
            label="赠备品验收数量"
            v-if="judgeShow('purthList-thc01')"
          >
            <u-input v-model="item.thc01" placeholder="" disabled></u-input>
          </u-form-item>
          <u-form-item label="检验人员" v-if="judgeShow('purthList-thudf08')">
            <u-input v-model="item.thudf08" placeholder="" disabled></u-input>
          </u-form-item>
        </view>
      </view>
    </u-form>
  </view>
</template>

<script>
import { getPurtg } from "@/api/workFlow/flowEngine";
import {
  getDataInterfaceDataInfo,
  getDictionaryDataSelector,
  getDataInterfaceRes,
} from "@/api/common";
import comMixin from "../mixin";
import {
  getGoodsList,
  getCustomerList,
  Info,
  Create,
  Update,
} from "@/api/apply/order";
import { getInfo } from "@/api/user";
export default {
  name: "crmOrder",
  mixins: [comMixin],
  data() {
    return {
      current: 0,
      swiperList: [
        {
          name: "交易信息",
        },
        {
          name: "发票信息",
        },
      ],
      hide: false,
      billEnCode: "OrderNumber",
      dataForm: {},
      permissionList: [],
      resultName: "",
      resultRadio: [
        {
          name: "允许",
          id: 1,
          disabled: true,
        },
        {
          name: "拒收",
          id: 2,
          disabled: true,
        },
        {
          name: "其他",
          id: 3,
          disabled: true,
        },
      ],
      resultEndName: "",
      resultEndRadio: [
        {
          name: "拒收",
          id: 1,
          disabled: true,
        },
        {
          name: "特采",
          id: 2,
          disabled: true,
        },
        {
          name: "挑选",
          id: 3,
          disabled: true,
        },
      ],
      lst: [],
      formConf: {},
      id: "",
      buyName: "",
      buyTwoName: "",
      shuizhoLst: [],
      dataForm: {}, //基本信息
      purthList: [], //进货信息
      moctiaList: [], //检测信息列表
      udf14Lst: [], //会签部门字段
    };
  },
  computed: {},
  methods: {
    init(data, id, flowFormContentJson) {
      this.setting = data;
      this.id = id;
      this.getInfo(data);
    },
    tabsChange(e) {
      this.current = e;
    },
    getInfo(data) {
      getPurtg(data.id).then((res) => {
        if (res.code == 200) {
          this.dataForm = res.data;
          this.purthList = res.data.purthList;
          this.gettg005(this.dataForm.tg005);
          this.gettg049(this.dataForm.tg049);
          this.gettg004(this.dataForm.tg004);
          this.getck();
          this.getTg042();
          this.getTg009();
        }
      });
    },
    gettg049(id) {
      let data = {
        id,
        interfaceId: "362111000289221189",
        propsValue: "ME001",
        relationField: "JoinStr",
      };

      getDataInterfaceDataInfo("381240499823979141", data).then((res) => {
        if (res.code == 200) {
          this.dataForm.tg049 = res.data.JoinStr;
        }
      });
    },

    gettg005(id) {
      let data = {
        id,
        interfaceId: "381247065990113925",
        dblink: this.id,
        propsValue: "MA001",
        relationField: "JoinStr",
      };
      getDataInterfaceDataInfo("381247065990113925", data).then((res) => {
        if (res.code == 200) {
          this.dataForm.tg005 = res.data.JoinStr;
        }
      });
    },
    gettg004(id) {
      let data = {
        id,
        interfaceId: "362111000289221189",
        propsValue: "MB001",
        relationField: "JoinStr",
      };
      getDataInterfaceDataInfo("362111000289221189", data).then((res) => {
        if (res.code == 200) {
          this.dataForm.tg004 = res.data.JoinStr;
        }
      });
    },
    getck() {
      for (let i = 0; i < this.purthList.length; i++) {
        let data = {
          id: this.purthList[i].th009,
          interfaceId: "381218413038545541",
          propsValue: "MC001",
          relationField: "JoinStr",
        };

        getDataInterfaceDataInfo("381218413038545541", data).then((res) => {
          if (res.code == 200) {
            this.dataForm.purthList[i].th009 = res.data.JoinStr;
          }
        });
      }
    },
    // 签核状态码

    getTg042() {
      console.log("tg042");
      getDictionaryDataSelector("411695330707391429").then((res) => {
        const obj = res.data.list.filter(
          (item) => item.enCode == this.dataForm.tg042
        )[0];
        this.dataForm.tg042 = obj ? obj.fullName : null;
      });
    },
    //
    getTg009() {
      getDictionaryDataSelector("382030349477096325").then((res) => {
        const obj = res.data.list.filter(
          (item) => item.enCode == this.dataForm.tg009
        )[0];
        this.dataForm.tg009 = obj ? obj.fullName : null;
      });
    },
    selfGetInfo() {
      Info(this.setting.id).then((res) => {
        this.dataForm = res.data;
        if (this.dataForm.fileJson) {
          this.fileList = JSON.parse(this.dataForm.fileJson);
        }
      });
    },
    selfSubmit() {
      this.dataForm.status = this.eventType === "submit" ? 0 : 1;
      if (this.eventType === "save") return this.selfHandleRequest();
      uni.showModal({
        title: "提示",
        content: "您确定要提交当前流程吗？",
        success: (res) => {
          if (res.confirm) {
            this.selfHandleRequest();
          }
        },
      });
    },
    selfHandleRequest() {
      if (!this.dataForm.id) delete this.dataForm.id;
      const formMethod = this.dataForm.id ? Update : Create;
      formMethod(this.dataForm).then((res) => {
        uni.showToast({
          title: res.msg,
          complete: () => {
            setTimeout(() => {
              uni.$emit("refresh");
              uni.navigateBack();
            }, 1500);
          },
        });
      });
    },
    initData() {
      getGoodsList().then((res) => {
        this.goodsOptions = res.data.list;
      });
      getCustomerList().then((res) => {
        this.customerOptions = res.data.list;
      });
    },
    selfInit() {
      this.addGoods();
      this.addPlan();
    },
    onChange(e) {
      const user = e[0];
      this.dataForm.salesmanName = user.fullName;
    },
    addGoods() {
      const item = {
        goodsId: "",
        goodsCode: "",
        goodsName: "",
        specifications: "",
        unit: "",
        qty: "",
        price: "",
        amount: "",
        discount: null,
        cess: null,
        actualPrice: "",
        actualAmount: "",
        description: "",
      };
      this.dataForm.goodsList.push(item);
    },
    delGoods(index) {
      this.dataForm.goodsList.splice(index, 1);
    },
    addPlan() {
      const item = {
        receivableDate: "",
        receivableRate: "",
        receivableMoney: "",
        receivableMode: "",
        abstract: "",
      };
      this.dataForm.collectionPlanList.push(item);
    },
    delPlan(index) {
      this.dataForm.collectionPlanList.splice(index, 1);
    },
    onGoodsChange(e, i) {
      const goods = e[0];
      this.dataForm.goodsList[i] = {
        goodsId: goods.id,
        goodsCode: goods.code,
        goodsName: goods.text,
        specifications: goods.specifications,
        unit: goods.unit,
        qty: 1,
        price: goods.price,
        amount: goods.price,
        discount: 100,
        cess: 0,
        actualPrice: goods.price,
        actualAmount: goods.price,
        description: "",
      };
      this.$forceUpdate();
    },
    onCustomerChange(e) {
      const customer = e[0];
      this.dataForm.customerName = customer.text;
    },
    count(row) {
      //金额 = 数量*单价
      row.amount = this.jnpf.toDecimal(
        parseFloat(row.price) * parseFloat(row.qty)
      );
      //折扣价 = (单价*折扣)
      var discountPrice = row.price * (row.discount / 100);
      //实际单价 = 折扣价 * (1 + (税率 / 100))
      row.actualPrice = this.jnpf.toDecimal(
        discountPrice * (1 + row.cess / 100)
      );
      //实际金额
      row.actualAmount = this.jnpf.toDecimal(
        parseFloat(row.actualPrice) * parseFloat(row.qty)
      );
      this.$forceUpdate();
    },
  },
};
</script>
